/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package FrameWork;

import FrameWork.Objects.Character.MyCharacter;
import javax.microedition.lcdui.Graphics;

/**
 *
 * @author DANTRUONG
 */
public class GameScreen {
    private Graphics m_Graphics;
    
    private int m_XView;
    private int m_YView;
    private Rectangle m_Rect;
    private int m_Height;
    private int m_Width;
    private ReadMap m_ReadMap;

    public Graphics getGraphics() {
        return m_Graphics;
    }

    public Rectangle getRect() {
        return m_Rect;
    }

    public int getXView() {
        return m_XView;
    }

    public int getYView() {
        return m_YView;
    }

    public int getHeight() {
        return m_Height;
    }

    public int getWidth() {
        return m_Width;
    }
    
    public void setGraphics(Graphics m_Graphics) {
        this.m_Graphics = m_Graphics;
    }

    public void setRect(Rectangle m_Rect) {
        this.m_Rect = m_Rect;
    }

    public void setXView(int m_XView) {
        this.m_XView = m_XView;
    }

    public void setYView(int m_YView) {
        this.m_YView = m_YView;
    }

    public void setHeight(int m_Height) {
        this.m_Height = m_Height;
    }

    public void setWidth(int m_Width) {
        this.m_Width = m_Width;
    }
    
    public GameScreen(){
        m_XView = 0; m_YView = 0;
        m_Rect = new Rectangle(0,0,0,0);
    }
    
    public GameScreen(Graphics _Graphics, Rectangle _Rect, ReadMap _ReadMap){
        m_Graphics  = _Graphics;
        m_Rect      = _Rect;
        m_XView     = (m_Rect.Right - m_Rect.Left)/2 + m_Rect.Left;
        m_YView     = (m_Rect.Bottom - m_Rect.Top)/2 + m_Rect.Top;
        m_Height    = m_Rect.Bottom - m_Rect.Top;
        m_Width     = m_Rect.Right - m_Rect.Left;
        m_ReadMap   = _ReadMap;
    }
    
    public void UpdateMove(MyCharacter _Player){
         if(_Player.getCurX() >= m_Width/2 ){
            if(_Player.getCurX() <= m_ReadMap.getWidth()*30 - m_Width/2){
                m_XView = (int)_Player.getCurX();
            }else{
                m_XView = m_ReadMap.getWidth()*30 - m_Width/2;
            }
        }
            
        if(_Player.getCurY() >= m_Height/2){
            if (_Player.getCurY() <= m_ReadMap.getHeight()*30 - m_Height/2){
                 m_YView = (int)_Player.getCurY();
            }else{
                m_YView = m_ReadMap.getHeight()*30 - m_Height/2;
            }
        }
        m_Rect = new Rectangle(m_XView - m_Width/2, m_YView - m_Height/2
                ,m_Width, m_Height);
    }
}
